import instance from '@/utils/request'

export function uploadAvatar(data) {
    return instance.request({
        method: 'post',
        url: '/user/upload-avatar',
        data,
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    })
}

export function uploadImage(data) {
    return instance.request({
        method: 'post',
        url: '/upload/post-image',
        data,
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    })
}

export function uploadMultipleImages(files) {
    const formData = new FormData()
    files.forEach(file => {
        formData.append('files', file)
    })

    return instance.request({
        method: 'post',
        url: '/upload/post-images',
        data: formData,
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    })
}

// 商品图片上传接口
export function uploadGoodImage(file) {
    const formData = new FormData()
    formData.append('file', file)

    console.log('上传文件信息:', {
        name: file.name,
        type: file.type,
        size: file.size
    })

    return instance.request({
        method: 'post',
        url: '/upload/good-image',
        data: formData,
        headers: {
            'Content-Type': 'multipart/form-data'
        },
        timeout: 30000 // 增加超时时间
    })
}

export function uploadMultipleGoodImages(files) {
    const formData = new FormData()
    files.forEach(file => {
        formData.append('files', file)
    })

    return instance.request({
        method: 'post',
        url: '/upload/good-images',
        data: formData,
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    })
}

export function deleteGoodImage(imageUrl) {
    return instance.request({
        method: 'delete',
        url: '/upload/good-image',
        data: {
            imageUrl
        }
    })
}
export function uploadResumeImage(file) {
  const formData = new FormData()
  formData.append('file', file)
  
  return instance.request({
    method: 'post',
    url: '/upload/resume', // 对应前端调用的接口路径
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}
